package com.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

//@Configuration
public class GzhPropertiesConfig {


    /**
     * 本地模式
     *
     * @return
     */
    @Bean("gzhConfig1")
    @Profile("dev")
    public GzhConfig gzhConfig_dev() throws Exception {
        GzhConfig config = new GzhConfig();
        Properties p = new Properties();
        InputStream is = GzhPropertiesConfig.class.getResourceAsStream("/gongzhonghao-dev.properties");
        try {
            p.load(is);
            config.setAppId(p.getProperty("wx.gzh.appId"));
            config.setAppSecret(p.getProperty("wx.gzh.appSecret"));
            config.setToken(p.getProperty("wx.gzh.token"));
            config.setEncodingAESKey(p.getProperty("wx.gzh.encodingAESKey"));
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        System.out.println(config.getAppId() + "   00000000");
        return config;
    }


    /**
     * 正式服务器
     *
     * @return
     */
    @Bean("gzhConfig2")
    @Profile("pro")
    public GzhConfig gzhConfig_pro() {
        GzhConfig config = new GzhConfig();
        Properties p = new Properties();
        InputStream is = GzhPropertiesConfig.class.getResourceAsStream("/gongzhonghao-pro.properties");
        try {
            p.load(is);

            config.setAppId(p.getProperty("wx.gzh.appId"));
            config.setAppSecret(p.getProperty("wx.gzh.appSecret"));
            config.setToken(p.getProperty("wx.gzh.token"));
            config.setEncodingAESKey(p.getProperty("wx.gzh.encodingAESKey"));
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        System.out.println(config.getAppId() + "   1111111111");
        return config;
    }

    /**
     * 测试服务器
     *
     * @return
     */
    @Bean("gzhConfig3")
    @Profile("test")
    public GzhConfig gzhConfig_test() {
        GzhConfig config = new GzhConfig();
        Properties p = new Properties();
        InputStream is = GzhPropertiesConfig.class.getResourceAsStream("/gongzhonghao-test.properties");
        try {
            p.load(is);

            config.setAppId(p.getProperty("wx.gzh.appId"));
            config.setAppSecret(p.getProperty("wx.gzh.appSecret"));
            config.setToken(p.getProperty("wx.gzh.token"));
            config.setEncodingAESKey(p.getProperty("wx.gzh.encodingAESKey"));
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        System.out.println(config.getAppId() + "   222222222");
        return config;
    }

}
